import React from "react";

import { fetchData,setStoreItem,getStoreItem} from '../../common';

import UIIcon from '../../uicomponents/UIIcon';

import {Badge,Select} from 'antd';

const Option = Select.Option;


/** 
 * 产品模型包选择
*/
export default class ProductModelDomainSelect extends React.Component {

	constructor(props) {
		super(props);
		this.modelDomainList = fetchData('PRODUCT/MODEL/productModelDomain/getModelDomains', {});
	}


	renderAppDoamin = (modelDomain) => {
		let color = "processing";
		if ('IN_USE' === modelDomain.status) {
			color = 'processing'
		}
		else if ('CLOSED' === modelDomain.status) {
			color = 'error'
		}

		return (<Badge status={color} style={{ marginLeft: 6 }} text={<span><UIIcon icon='cubes' />{modelDomain.domainName}</span>} />)
	}

	handleSelect = (value, opt) => {
		setStoreItem('lastSelectModelDomainId', value);
		if (this.props.onSelectModelDomain) {
			this.props.onSelectModelDomain(value);
		}
	}

	render() {
		const { modelDomainList } = this;
		return (
			<Select style={{ width: 250 }}
				onSelect={this.handleSelect}
				placeholder="请选择模型域"
				defaultValue={getStoreItem('lastSelectModelDomainId',0)}
			>
				{modelDomainList.map(modelDomain => (
					<Option key={modelDomain.id} value={modelDomain.id + ''}>{this.renderAppDoamin(modelDomain)}</Option>
				))}
			</Select>
		);
	}
}
